# graphics/draw_stickman.py
# 使用 Pygame 绘制一个简单的二维火柴人
# 由头（圆形）和身体、四肢（线条）组成
# 适合初学者理解基本图形绘制

import pygame
from config import STICKMAN_COLOR, STICKMAN_RADIUS


def draw_stickman(screen, stickman):
    """
    在指定的 screen 上绘制火柴人

    参数:
        screen: Pygame 的屏幕对象 (pygame.Surface)
        stickman: Stickman 类的实例，包含 x, y 位置等信息
    """
    # === 1. 提取火柴人中心位置（头的中心）===
    x = int(stickman.x)
    y = int(stickman.y)

    # === 2. 画头部（圆形）===
    pygame.draw.circle(screen, STICKMAN_COLOR, (x, y), STICKMAN_RADIUS)

    # === 3. 画身体（从头到躯干底部）===
    body_length = 30  # 身体长度（头以下）
    body_end_y = y + body_length
    pygame.draw.line(screen, STICKMAN_COLOR, (x, y + STICKMAN_RADIUS), (x, body_end_y), 2)

    # === 4. 画左腿（从身体底部向左下）===
    left_leg_end_x = x - 15
    left_leg_end_y = body_end_y + 20
    pygame.draw.line(screen, STICKMAN_COLOR, (x, body_end_y), (left_leg_end_x, left_leg_end_y), 2)

    # === 5. 画右腿（从身体底部向右下）===
    right_leg_end_x = x + 15
    right_leg_end_y = body_end_y + 20
    pygame.draw.line(screen, STICKMAN_COLOR, (x, body_end_y), (right_leg_end_x, right_leg_end_y), 2)

    # === 6. 画左臂（从肩部向左）===
    arm_y = y + 10  # 手臂起始高度（头下方）
    left_arm_end_x = x - 20
    left_arm_end_y = arm_y + 10
    pygame.draw.line(screen, STICKMAN_COLOR, (x - 5, arm_y), (left_arm_end_x, left_arm_end_y), 2)

    # === 7. 画右臂（从肩部向右）===
    right_arm_end_x = x + 20
    right_arm_end_y = arm_y + 10
    pygame.draw.line(screen, STICKMAN_COLOR, (x + 5, arm_y), (right_arm_end_x, right_arm_end_y), 2)

    # 注意：目前四肢是固定姿势，后续可扩展为根据动作摆动